<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
   
    <style>
            div{
                width: 800px;
            }
        ul{
            list-style: none;
            overflow: hidden;
            padding-left: 0;
        }
        ul.container li{
            float: left;
            height: 40px;
            line-height: 40px;
            width: 80px;
            background-color:#ccc;
            color: #333;
            text-align: center;
        }
        button{
            background-color: #ccc;
            color:#333;
            padding: 10px;
        }
        .item{
            background: #ccc;
            padding:10px;
            margin:10px auto;
        }
        .biaodan{
            background: #ccc;
            padding: 10px;
        }
        .biaodan1{
            margin:10px 0;
        }
        .container .biaodan1 input{
            padding: 10px;
            border:1px solid #ccc;
            width: 400px;
        }
        .container li.active{
            color:#FFF;
            background-color: #0075B6;
        }
    </style>
    
</head>
<body>
    <div id="app">
        <ul class="container">
            <li @click="changePinglun(1)" :class="pinglun === 1 ? 'active' : ''" >评论管理</li>
            <li @click="changePinglun(2)" :class="pinglun === 2 ? 'active' : ''">发布评论</li>
        </ul>
        <div>
            <div class="content" v-show="pinglun === 1">
                <ul v-if="contents.length > 0">
                    <li class="item"  v-for="item in contents" :key="item.time">
                        <h6>评论人: {{item.name}}</h6>
                        <h6>评论时间: {{item.time}}</h6>
                        <h6>评论内容: {{item.content}}</h6>
                    </li>
                </ul>
                <ul v-else >
                    <li>暂无数据</li>
                </ul>
            </div>
            <!-- 表单内容区域 -->
            <div class="biaodan" v-show="pinglun === 2">
                <div class="biaodan1">
                    <input v-model="user.name" type="text" placeholder="昵称" id="name">
                </div>
                <div class="biaodan1">
                    <input v-model="user.content" type="text" placeholder="评论内容" id="content">
                </div>
                <div class="biaodan1">
                    <button class="btn" @click="tijiao">立即提交</button>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="./js/vue.js"></script>
<script>
    new Vue({
el:'#app',
data:{
        pinglun:1,
        user:{
            name:'',
            content:'',
        },
        contents:[],//评论管理
    },
    methods:{
        changePinglun(num){
            this.pinglun = num;
        },
        tijiao(){
            let username = {
                //    user:this.user,
                ...this.user,
                time: new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString(),
            }
            this.contents.push(username);
            this.pinglun = 1; 
        }
        }
    })
</script>

</html>